package controller

import (
	"learning/gooop/spring/demo/order/dto"
	"learning/gooop/spring/demo/order/entity"
	"learning/gooop/spring/demo/order/service"
)

// OrderController handles rest requests for CRUD orders
// @RestController
// @RequestMapping path=/order
type OrderController struct {
	orderService service.IOrderService
}

// Save create or update an order
// @PostMapping
func (me *OrderController) Save(head *entity.OrderHeadEntity, items []*entity.OrderItemEntity) error {
	return me.orderService.Save(head, items)
}

// View gets order and order items
// @GetMapping
func (me *OrderController) View(orderID int) (error, *dto.OrderDTO) {
	return me.orderService.Get(orderID)
}

// Query query order headers by custom conditions
// @GetMapping
func (me *OrderController) Query(customerID int, statusFlag int, dateFrom string, dateTo string, pageNO int, pageSize int) (error, []*dto.OrderHeadDTO) {
	return me.orderService.Query(customerID, statusFlag, dateFrom, dateTo, pageNO, pageSize)
}
